<template>
  <div class="login_container">
    <div class="login_box">
      <!--头像区域-->
      <div class="avatar_box">
        <img src="../assets/logo.png" alt="logo">
      </div>
      <span class="title">欢迎登录资产管理系统</span>
      <!--  表单区域-->
      <div class="form_box">
        <a-form
            :model="formState"
            name="basic"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 16 }"
            autocomplete="off"
            @finish="onFinish"
            @finishFailed="onFinishFailed"
        >
          <a-form-item
              label="用户名"
              name="username"
              :rules="[{ required: true, message: 'Please input your username!' }]"
          >
            <a-input v-model:value="formState.username"/>
          </a-form-item>

          <a-form-item
              label="密码"
              name="password"
              :rules="[{ required: true, message: 'Please input your password!' }]"
          >
            <a-input-password v-model:value="formState.password"/>
          </a-form-item>

          <a-form-item name="isRememberMe" :wrapper-col="{ offset: 8, span: 16 }">
            <a-checkbox v-model:checked="formState.isRememberMe">Remember me</a-checkbox>
          </a-form-item>

          <a-form-item :wrapper-col="{ offset: 8, span: 16 }">
            <a-button type="primary" html-type="submit">登录</a-button>
          </a-form-item>
        </a-form>

      </div>

    </div>
  </div>
</template>

<script>
import { message, } from 'ant-design-vue';
import {reactive, defineComponent, ref} from 'vue';
import {login} from "@/apis/user";
import router from "@/router/router";

export default defineComponent({
  setup() {
    const formState = reactive({
      username: '',
      password: '',
      isRememberMe: true,
    });

    const onFinish = values => {
      login(formState).then(res => {
        if (res.status === '0') {
          console.log("登录成功", res)
          message.success('登录成功');
          window.sessionStorage.setItem("token",res.data)
          router.push('/home')
        }

      })
    };

    const onFinishFailed = errorInfo => {
    };

    return {
      formState,
      onFinish,
      onFinishFailed
    };
  }
})
</script>

<style scoped lang="less">
.login_container {
  background-image: url("../assets/backgroud.png");
  height: 100%;
}

.login_box {
  width: 450px;
  height: 350px;
  background-color: #fff;
  border-radius: 3px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);

}

.avatar_box {
  height: 130px;
  width: 130px;
  border-radius: 50%;
  padding: 10px;
  box-shadow: 0 0 10px #eee;
  position: absolute;
  left: 50%;
  top: -50%;
  transform: translate(-50%, 50%);

  img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background-color: #eee;
  }
}

.form_box {
  position: absolute;
  bottom: 0;
  width: 100%;
  transform: translate(-8%);
}

.title{
  position: absolute;
  left: 50%;
  top: 10%;
  font-size: 20px;
  transform: translate(-50%);
}

</style>